package mysql

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"travel/project/appconfig"
	"travel/project/global"
)

var Ctx = context.Background()

func Init() {
	RedisName := appconfig.AppName.Redis
	Addr := fmt.Sprintf("%s:%d", RedisName.Host, RedisName.Port)
	global.RDB = redis.NewClient(&redis.Options{
		Addr:     Addr,
		Password: RedisName.Password, // no password set
		DB:       0,                  // use default DB
	})

	err := global.RDB.Set(Ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	fmt.Println("Redis 连接成功")
}
